//
//  HomeViewController.m
//  KeleAppProject
//
//  Created by 周岑 on 2018/1/11.
//  Copyright © 2018年 Cen Zhou. All rights reserved.
//

#import "HomeViewController.h"


#import "RecommendVC.h"
#import "HotestVC.h"
#import "NewestVC.h"


#import "SearchViewController.h"
@interface HomeViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) NSArray *titleArray;
@property (nonatomic, strong) NSArray *controlerArray;

@property (nonatomic, assign) BOOL isPush;
@end

@implementation HomeViewController


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.isPush = NO;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    if (self.isPush) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    }
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self configureNavTitleViewWithDataSource:self.titleArray width:32 distance:30 notificationName:@"SortScrollToIndex"];
    [self addChildControllersWithArray:self.controlerArray];
    [self loadSubviewsOnHomeWithScrollHeight:KLScreenH-NaviH-TabbarH y:0 titleArr:self.titleArray];
    UIBarButtonItem *rightBarBtn = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"icon_sousuo"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]  style:UIBarButtonItemStyleDone target:self action:@selector(search)];
    self.navigationItem.rightBarButtonItem = rightBarBtn;

}

- (void)search{
    self.isPush = YES;
    SearchViewController *searchVc = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchVc animated:YES];
}

- (NSArray *)titleArray
{
    if (!_titleArray) {
        _titleArray = [NSArray arrayWithObjects:@"推荐",@"最新",@"最火", nil];
    }
    return _titleArray;
}

- (NSArray *)controlerArray{
    if (!_controlerArray) {
        _controlerArray = [NSArray arrayWithObjects:@"RecommendVC",@"HotestVC",@"NewestVC", nil];
    }
    return _controlerArray;
}


- (void)dealloc {
    NSLog(@"HomePageViewController控制器被销毁了");
}
//


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
